/**
 * SPDX-FileCopyrightText: 2023-2025 Sangfor Technologies Inc.
 * SPDX-License-Identifier: Mulan PSL v2
 */
/**
 * Created by czh on 2019/5/31.
 */

const CHROME49 = 49;
const FIREFOX52 = 52;
const IE11 = 11;

/**
 * 检测浏览器兼容性是否支持
 * @return {boolean}
 */
function checkBrowserVisibility (): boolean {
    let ua = navigator.userAgent;
    let mt;

    // isChrome49p
    mt = ua.match(/Chrome\/(\d+)/i);
    if (mt && Number(mt[1]) >= CHROME49) {
        return true;
    }

    //  isFirefox52p
    mt = ua.match(/Firefox\/(\d+)/i);
    if (mt && Number(mt[1]) >= FIREFOX52) {
        return true;
    }

    //  isIE11p
    if ((document as SafeAny).documentMode >= IE11) {
        return true;
    }

    return false;
}

let isBrowserVisibility = checkBrowserVisibility();

import {
    PLATFORM_INFO
// eslint-disable-next-line
// @ts-ignore
} from 'src/home/mod_common/const';

import {
    getStorage
} from 'src/util/local_storage';

function getInfoFromStorage (): SafeAny {
    let str = getStorage(PLATFORM_INFO);
    if (!str) {
        return null;
    }

    let ret;
    try {
        ret = JSON.parse(str);
    } catch (e) {
        ret = null;
    }

    return ret;
}

export {
    isBrowserVisibility,
    getInfoFromStorage
};
